package krow.dev.gunpobus;

import java.util.ArrayList;
import java.util.List;

import krow.dev.gunpobus.model.TabItem;
import krow.dev.gunpobus.util.DebugHelper;
import krow.dev.gunpobus.view.PagerSlidingTab;
import krow.dev.gunpobus.view.adapter.TabPageAdapter;
import krow.dev.gunpobus.view.fragment.FavoriteFragment;
import krow.dev.gunpobus.view.fragment.RouteFragment;
import krow.dev.gunpobus.view.fragment.StationFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

public class MainActivity extends FragmentActivity {

	private TabPageAdapter mTabPageAdapter;
	private PagerSlidingTab mPagerSlidingTab;
	private ViewPager mViewPager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if(!GlobalStore.getInstance().isAvailable()){
			Intent intent = new Intent(this, SplashActivity.class);
			startActivity(intent);
			finish();
		}
		
		initializeView();
	}
	
	private void initializeView(){
		DebugHelper.d("MainActivity - initializeView()");
		
		List<TabItem> tabItemList = new ArrayList<TabItem>();
		TabItem tabItem = new TabItem();
		tabItem.setName(getString(R.string.tab_favorite));
		tabItem.setFragment(FavoriteFragment.class);
		tabItemList.add(tabItem);
		
		tabItem = new TabItem();
		tabItem.setName(getString(R.string.tab_route));
		tabItem.setFragment(RouteFragment.class);
		tabItemList.add(tabItem);
		
		tabItem = new TabItem();
		tabItem.setName(getString(R.string.tab_station));
		tabItem.setFragment(StationFragment.class);
		tabItemList.add(tabItem);
		
		mTabPageAdapter = new TabPageAdapter(getSupportFragmentManager(), tabItemList);
		mViewPager = (ViewPager) findViewById(R.id.viewpager);
		mViewPager.setOffscreenPageLimit(2);
		mViewPager.setAdapter(mTabPageAdapter);
		mViewPager.setCurrentItem(GlobalStore.getInstance().getStartPageIndex());
		mPagerSlidingTab = (PagerSlidingTab) findViewById(R.id.indicator_tab);
		mPagerSlidingTab.setShouldExpand(true);
		mPagerSlidingTab.setViewPager(mViewPager);
	}
	
//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		getMenuInflater().inflate(R.menu.main, menu);
//		return true;
//	}
	
}
